library funcFunc;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes;

const
  TwoPi = 6.283185307179586;

type TStrParams = array of String;
     TArrayValues = array of Double;

{$R *.res}

function getParamsCount:Integer; export;
begin
  Result := 3;
end;

function getParamLabel(index: Integer): String;
begin
  Case index of
       0 : Result := 'a';
       1 : Result := 'b';
       2 : Result := 'c';
    else Result := '';
  end;
end;

function functionX(x: Double; params: array of Double):Double; export;
begin
  if Length(params) > 2 then
      Result := sin(2*Pi*params[0]*x) + sin(2*Pi*params[1]*x) +
                                                sin(2*Pi*params[2]*x)
  else
      Result := 0;
end;

function getName: String; export;
begin
  Result := 'f(x,a,b,c)';
end;

function checkParams(params: array of Double): Boolean; export;
var i: Integer;
  res: Boolean;
begin
  res := true;
  if Length(params) > 2 then
  for i := 0 to 2 do
     if ((params[i] < 0) or (params[i] > 500)) then
        res := false;
  Result := res;
end;

function getParamsRequirementsText: String; export;
begin
  Result := '0<=a<=500; 0<=b<=500; 0<=c<=500;';
end;

exports getParamsCount name 'getParamsCount';
exports functionX name 'functionX';
exports getParamLabel name 'getParamLabel';
exports getName name 'getName';
exports checkParams name 'checkParams';
exports getParamsRequirementsText name 'getParamsRequirementsText';

begin
end.
